﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;
using Common;

namespace Workflow.Project
{
    public partial class SearchNode3 : System.Web.UI.Page
    {
        private PJSearchManager objPJSearch = new PJSearchManager();
        public List<PJNode> resultList = new List<PJNode>();
        public SearchChoose objSearchChoose = new SearchChoose();
        public string fot;
        public string ots;
        public string ppap;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            string pjId = txtNo1.Text.ToString().Trim().ToUpper();
            DateTime date1 = Convert.ToDateTime(txtCompleteDate1.Text);
            DateTime date2 = Convert.ToDateTime(txtCompleteDate2.Text);
            string createrName = txtPJCreater.Text.ToString().Trim();
            resultList = objPJSearch.GetNode(pjId, createrName, date1, date2);
            List<PJNode> fotList = new List<PJNode>();
            List<PJNode> otsList = new List<PJNode>();
            List<PJNode> ppapList = new List<PJNode>();

            fotList = resultList.Where(s => (s.NodeName == "FOT")).ToList();
            otsList = resultList.Where(s => (s.NodeName == "OTS")).ToList();
            ppapList = resultList.Where(s => (s.NodeName == "PPAP")).ToList();

            if (fotList.Count > 0)
            {
                fot = Complete(fotList);
            }
            else
            {
                fot = "没有数据";
            }
            if (otsList.Count > 0)
            {
                ots = Complete(otsList);
            }
            else
            {
                ots = "没有数据";
            }
            if (ppapList.Count > 0)
            {
                ppap = Complete(ppapList);
            }
            else
            {
                ppap = "没有数据";
            }

        }
        private string Complete(List<PJNode> list)
        {
            double temp1 = 0;
            double temp2 = list.Count;
            foreach (var item in list)
            {
                if (item.RealCompleteDate != Convert.ToDateTime("1900-01-01") && item.RealCompleteDate <= item.CompleteDate)
                {
                    temp1++;
                }
            }
            double tempFot = temp1 / temp2;
            return string.Format("{0:P}", tempFot);
             
        }

        protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            string msgForm = objSearchChoose.Choose(ddlSelect);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", msgForm);
        }
    }
}